package org.example.utils;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
//@Schema(name = "Result" ,description = "请求返回结果封装对象")
public class Result<T>{
//    @Schema(description = "响应编码")
    private Integer code;

//    @Schema(description = "响应信息")
    private String message;

//    @Schema(description = "响应结果")
    private T data;

    private Result(){}
    private static <T> Result<T> bulid(T data){
        Result<T> result = new Result<>();
        if(data != null){
            result.setData(data);
        }
        return result;
    }

//    public static <T> Result<T> build(T data,Integer code,String message){
//        Result<T> result = new Result<>();
//        result.bulid(data);
//        result.setCode(code);
//        result.setMessage(message);
//        return result;
//    }
//
//    public static <T> Result<T> build(T data,ResultEnumCode resultEnumCode){
//        Result<T> result = new Result<>();
//        result.bulid(data);
//        result.setCode(resultEnumCode.getCode());
//        result.setMessage(resultEnumCode.getMessage());
//        return result;
//    }

    public static <T> Result<T> ok(T data){
        Result<T> result = new Result<>();
        if(data !=null){
            result.setData(data);
        }
        result.setCode(200);
        result.setMessage("success");
        return result;
    }

    public static <T> Result<T> error(String Message){
        Result<T> result = new Result<>();
        result.setCode(500);
        if(Message !=null){
            result.setMessage(Message);
        }
        return result;
    }

    public static <T> Result<T> warning(Integer code,String Message){
        Result<T> result = new Result<>();
        result.setCode(code);
        if(Message !=null){
            result.setMessage(Message);
        }
        return result;
    }

}
